package online.siwu.memorycards

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.KeyEvent
import android.widget.SimpleAdapter
import kotlinx.android.synthetic.main.activity_code_list.*


class CodeListActivity : AppCompatActivity() {

    val GD = GlobalData

    val from = arrayOf("num", "code")  //定义key的名字
    val to = intArrayOf(R.id.tvNumber, R.id.tvCode110)  //key所对应的控件id

    val list: ArrayList<HashMap<String, String>> = ArrayList()
    var map: HashMap<String, String> = HashMap()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_code_list)

        btOK.setOnClickListener { finish() }
        btEdit.setOnClickListener { gotoActivity<EditActivity>() }
        //创建map对象
        for (i in 0..109) {
            map = HashMap()
            map.put("num", GD.int2str110(i))
            map.put("code", GD.arrCode[i] as String)
            list.add(map)
        }
        //为ListView设置适配器
        lvCode110.adapter = SimpleAdapter(this, list, R.layout.list_code_list, from, to)
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK)
            finish()
        return false
    }
}
